Skip to content

Avoid making object arrays for mask in cubeviz to speed up loading large cubes#3787

Merged
kecnry merged 3 commits into
spacetelescope:mainfrom
astrofrog:avoid-object-array
Sep 17, 2025
Merged

Avoid making object arrays for mask in cubeviz to speed up loading large cubes#3787
kecnry merged 3 commits into
spacetelescope:mainfrom
astrofrog:avoid-object-array

Conversation

@astrofrog
Copy link
Copy Markdown
Collaborator

@astrofrog astrofrog commented Sep 17, 2025

Description

Before this PR, if the mask was None as returned by the NDData's .mask attribute, np.logical_or was returning object arrays:

In [2]: np.logical_or(None, np.array([1, 0, 1], dtype=bool))
Out[2]: array([True, False, True], dtype=object)

Object arrays are very memory and CPU inefficient. This PR avoids this by only doing a logical OR if the original mask is not None. This speeds up the initial loading of large cubes into cubeviz by a factor of 3x on my machine (I tested this for a 3.4GB cube).

Change log entry

  • Is a change log needed? If yes, is it added to CHANGES.rst? If you want to avoid merge conflicts,
    list the proposed change log here for review and add to CHANGES.rst before merge. If no, maintainer
    should add a no-changelog-entry-needed label.

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • Are two approvals required? Branch protection rule does not check for the second approval. If a second approval is not necessary, please apply the trivial label.
  • Do the proposed changes actually accomplish desired goals? Also manually run the affected example notebooks, if necessary.
  • Do the proposed changes follow the STScI Style Guides?
  • Are tests added/updated as required? If so, do they follow the STScI Style Guides?
  • Are docs added/updated as required? If so, do they follow the STScI Style Guides?
  • If new remote data is added that uses MAST, is the URI added to the cache-download.yml workflow?
  • Did the CI pass? If not, are the failures related?
  • Is a milestone set? Set this to bugfix milestone if this is a bug fix and needs to be released ASAP; otherwise, set this to the next major release milestone. Bugfix milestone also needs an accompanying backport label.
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@github-actions github-actions Bot added cubeviz plugin Label for plugins common to multiple configurations labels Sep 17, 2025
@astrofrog astrofrog added this to the 4.4 milestone Sep 17, 2025
Copy link
Copy Markdown
Collaborator

@rosteen rosteen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks!

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.52%. Comparing base (7c1bf61) to head (5025b02).
⚠️ Report is 129 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3787      +/-   ##
==========================================
- Coverage   86.52%   86.52%   -0.01%     
==========================================
  Files         180      180              
  Lines       24706    24708       +2     
==========================================
+ Hits        21377    21378       +1     
- Misses       3329     3330       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kecnry kecnry merged commit bc11eaf into spacetelescope:main Sep 17, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cubeviz plugin Label for plugins common to multiple configurations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants